﻿using System.Diagnostics;
using GeneralMethodClass.Document;

namespace GeneralMethodClass.Sys
{
    public static class ProcessOP
    {
        /// <summary>
        /// 关闭应用程序
        /// </summary>
        /// <param name="ArrayProcessName">应用程序名之间用‘,’分开</param>
        public static void CloseApp(string ArrayProcessName)
        {
            string[] processName = ArrayProcessName.Split(',');
            foreach (string appName in processName)
            {
                Process[] localByNameApp = Process.GetProcessesByName(appName);//获取程序名的所有进程
                if (localByNameApp.Length > 0)
                {
                    foreach (var app in localByNameApp)
                    {
                        if (app.ProcessName.Equals(appName))
                        {
                            app.Kill();
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 开启进程
        /// </summary>
        /// <param name="ArrayFolderPath">需要开启进程文件夹的路径，多个路径用‘,’隔开;eg:d:\test,e:\temp</param>
        public static void StartApp(string ArrayFolderPath)
        {
            string[] foldersNamePath = ArrayFolderPath.Split(',');
            foreach (string folderNamePath in foldersNamePath)
            {
                FileOP.GetFolderApp(folderNamePath, "exe");
            }
        }
    }
}
